package io.wongxd.demo.page.views

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.wongxd.demo.M
import io.wongxd.solution.baseView.BaseComposeToolBarFgt
import io.wongxd.solution.compose.composeTheme.*
import io.wongxd.solution.compose.custom.views.other.FpsText
import io.wongxd.solution.compose.custom.views.value_selector.*
import io.wongxd.solution.compose.custom.views.value_selector.date_time_selector.WDateTimeSelector
import io.wongxd.solution.compose.custom.views.value_selector.date_time_selector.WDateTimeSelectorState

class FgtViewValueSelector : BaseComposeToolBarFgt() {
    override fun lazyInit() {

    }

    override val title: String
        get() = "FgtViewValueSelector"

    @Composable
    override fun Render() {
        ComposeContent()
    }

    @Composable
    private fun ComposeContent() {

        FpsText()

        Column(
            M
                .fillMaxSize()
                .verticalScroll(rememberScrollState()),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {

//            ValueSample()
//            ValuesSample()
            DateSample()
            DateTimeSample()

            Box(modifier = Modifier.height(80.dp))
        }
    }

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    private fun DateTimeSample() {
        val state = remember { WDateTimeSelectorState(2022, 2, 5) }
        WDateTimeSelector(
            state,
            modifier = Modifier.padding(horizontal = 5.dp),
            dateDividerString = Triple("年", "月", "日"),
            dateDividerTextStyle = AppThemeHolder.textStyle.sp12.appColor(),
            selectedTextColor = AppThemeHolder.colorAssets.appColor,
            isShowTime = true,
            isShowSecond = true,
            timeDividerString = Triple("时", "分", "秒"),
        )
        Button({
            "${state.getYear()}.${state.getMonth()}.${state.getDay()} ${state.getHour()}:${state.getMinute()}:${state.getSecond()}".showToast()
        }) {
            Text("获取当前值")
        }
    }

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    private fun DateSample() {
        val state = remember { WDateTimeSelectorState(2022, 2, 5) }
        WDateTimeSelector(
            state,
            dateDividerString = Triple("年", "月", "日"),
            dateDividerTextStyle = AppThemeHolder.textStyle.sp14.appColor(),
            selectedTextColor = AppThemeHolder.colorAssets.appColor
        )
        Button({
            "${state.getYear()}.${state.getMonth()}.${state.getDay()}".showToast()
        }) {
            Text("获取当前值")
        }
    }

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    private fun ValuesSample() {
        val values = remember {
            listOf(
                (1900..2022).map(Int::toString).toTypedArray(),
                (1..12).map(Int::toString).toTypedArray(),
            )
        }
        val states = remember {
            listOf(
                WValueSelectState(),
                WValueSelectState(),
            )
        }
        WValuesSelector(
            values,
            states,
        )
        Button({
            values.mapIndexed { index, strings ->
                strings[states[index].getSelectIndex()]
            }.joinToString().showToast()
        }) {
            Text("获取当前值")
        }
    }

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    private fun ValueSample() {
        val values = remember { ((0 until 60).map(Int::toString)).toTypedArray() }
        val state = rememberValueSelectState()
        WValueSelector(
            values = values,
            state = state,
            defaultSelectIndex = 10,
            //isLoop = true,
            //cacheSize = 4,
            //textColors = arrayListOf(
            //    Color.Black, Color.Red, Color.Green, Color.Blue
            //),
            //textSizes = arrayListOf(
            //    16.sp, 14.sp, 12.sp, 10.sp,
            //)
        )
        Button({
            values[state.getSelectIndex()].showToast()
        }) {
            Text("获取当前值")
        }
    }

    @Preview(showBackground = true, backgroundColor = 0xffffffff)
    @Composable
    fun RenderPreView() {

    }
}